import { request } from '../../request/index'

// pages/activityDetail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activity: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    let user = wx.getStorageSync('user')
    if (!user) {
      wx.navigateTo({url: '../login/login'})
      return
    }
    const id = e.id
    request({url: "/activity/" + id, method: 'GET'}).then(res => {
        this.setData({
          activity: res.data
        })
      })
  },
  reserve() {
    const id = this.data.activity.id
    const name = this.data.activity.name
    const user = wx.getStorageSync('user')
    const data = { activityId: id, activityName: name,  userId: user.id, userName: user.nickname, state: '待确认'}
    request({url: "/activityUser", data: data, method: 'POST'}).then(res => {
      if (res.code === '200') {
         wx.showToast({title: '预约成功', icon: 'success'})
      } else {
         wx.showToast({title: res.msg, icon: 'none'})
      }
    })
  }
})